﻿using System;
using System.Collections.Generic;
using System.Text;
using Framework.Platform.Components.UI.Field;

namespace Framework.Platform.Components.UI.View
{
    /// <summary>
    /// 视图位置。
    /// </summary>
    public enum ViewPosition
    {
        Left,
        Right,
        Top,
        Bottom,
        Middle,
        Float
    }
    /// <summary>
    /// 视图状态
    /// </summary>
    public enum ViewStatus
    {
        /// <summary>
        /// 查看状态
        /// </summary>
        View,
        /// <summary>
        /// 编辑状态
        /// </summary>
        Edit,
        /// <summary>
        /// 新增状态
        /// </summary>
        New,
        /// <summary>
        /// 不可用状态
        /// </summary>
        Disable
    }

    public interface IView : IDisposable
    {
        #region 属性
        /// <summary>
        /// 视图标识
        /// </summary>
        string ViewKey { get; set; }
        /// <summary>
        /// 视图名称
        /// </summary>
        string ViewName { get; set; }
        /// <summary>
        /// 视图所在位置。
        /// </summary>
        ViewPosition Position { get; set; }
        /// <summary>
        /// 是否能关闭
        /// </summary>
        bool Closeable { get; set; }
        /// <summary>
        /// 视图数据
        /// </summary>
        object ViewDataSource { get; set; }
        /// <summary>
        /// 视图初始化对象
        /// </summary>
        object InitViewData { get; set; }
        /// <summary>
        /// 视图状态
        /// </summary>
        ViewStatus Status { get; set; }
        /// <summary>
        /// 
        /// </summary>
        bool ReadOnly { get; set; }
        #endregion

        #region 方法
        #region 字段操作方法
        /// <summary>
        /// 获取视图的所有字段
        /// </summary>
        /// <returns></returns>
        ICollection<IField> GetFields();
        /// <summary>
        /// 通过键值获取字段
        /// </summary>
        /// <param name="fieldKey"></param>
        /// <returns></returns>
        IField GetFieldByKey(string fieldKey);
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="field"></param>
        void AddField(IField field);
        /// <summary>
        /// 删除字段
        /// </summary>
        /// <param name="fieldKey"></param>
        void RemoveFieldByKey(string fieldKey);
        #endregion

        #region 视图指令方法
        /// <summary>
        /// 获取视图的所有视图命令
        /// </summary>
        /// <returns></returns>
        ICollection<ViewCommander> GetViewCommanders();
        /// <summary>
        /// 通过键值获取视图命令
        /// </summary>
        /// <param name="commanderKey"></param>
        /// <returns></returns>
        ViewCommander GetViewCommanderByKey(string commanderKey);
        /// <summary>
        /// 添加视图命令
        /// </summary>
        /// <param name="viewCommander"></param>
        void AddViewCommander(ViewCommander viewCommander);
        /// <summary>
        /// 删除视图命令
        /// </summary>
        /// <param name="commanderKey"></param>
        void RemoveViewCommanderByKey(string commanderKey);
        #endregion

        /// <summary>
        /// 绑定视图数据
        /// </summary>
        void ViewDataBind();
        /// <summary>
        /// 验证视图
        /// </summary>
        void ViewValidate();
        #endregion

        #region 事件
        /// <summary>
        /// 当视图事件被激发
        /// </summary>
        event EventHandler<ViewEventArgs> ViewEventRaise;
        #endregion
    }

    public class ViewEvents
    {
        public const string OnViewLoad = "ViewLoad";

        public const string OnViewClosed = "ViewClosed";
    }
}
